package com.tongshu.naive.chat.socket.handler;

import com.tongshu.naive.chat.application.UIService;
import com.tongshu.naive.chat.socket.MyBizHandler;
import com.tongshu.naive.chat.ui.view.chat.IChatMethod;
import io.netty.channel.Channel;
import javafx.application.Platform;
import protocol.friend.SearchFriendResponse;
import protocol.friend.dto.UserDto;

import java.util.List;

public class SearchFriendHandler extends MyBizHandler<SearchFriendResponse> {
    public SearchFriendHandler(UIService uiService) {
        super(uiService);
    }

    @Override
    public void channelRead(Channel channel, SearchFriendResponse msg) {
        List<UserDto> list = msg.getList();
        if (null == list || list.isEmpty()) return;
        IChatMethod chatMethod = uiService.getiChatMethod();
        Platform.runLater(()->{
            for (UserDto userDto : list) {
                chatMethod.addLuckFriend(userDto.getUserId(), userDto.getUserNickName(), userDto.getUserHead(), userDto.getStatus());
            }
        });
    }
}
